package com.oil.petro.eshop.controller;

import com.oil.petro.eshop.bean.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TestController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public ModelAndView showProductList() {
        // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
        // Account account = new Account("login4", "password4", "email4", 1);

        List<String> categroyList = new ArrayList<String>();

        categroyList.add("Monitory");
        categroyList.add("Komputery");
        categroyList.add("Laptopy");
        categroyList.add("Myszki");
        categroyList.add("Klawiatury");
        categroyList.add("Drukarki");
        categroyList.add("Dyski");
        categroyList.add("Akcesoria");
        categroyList.add("Głosniki");
        Map<String, Object> model = new HashMap<String, Object>();
       //  model.put("person", person);
        //  model.put("account", account);
//        model.put("email", account.getEmail());
//         model.put("login", account.getLogin());
//          model.put("password", account.getPassword());
//        model.put("firstname", person.getFirstName());
//         model.put("lastname", person.getLastName());
//          model.put("city", person.getCity());
//            model.put("address", person.getAddress());
//            model.put("postcode", person.getPostCode());

        Test test = new Test();
        System.out.println("Dupaaaa");
        //model.put("status",0);
        model.put("Test", test);
            //ModelAndView mv = new ModelAndView();
        //mv.addObject("/Test", test);  
        //return mv;

        return new ModelAndView("/Test", model);

    }

//    @RequestMapping(value = "/test", method = RequestMethod.POST)
//    public ModelAndView executeSubmitOnProductListPage(@ModelAttribute("Test") Test test, BindingResult result, SessionStatus status, HttpServletRequest request) {
//       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
//        // Account account = new Account("login4", "password4", "email4", 1);
//
////        List<String> categroyList = new ArrayList<String>();
////        
////        categroyList.add("Monitory");
////        categroyList.add("Komputery");
////        categroyList.add("Laptopy");
////        categroyList.add("Myszki");
////        categroyList.add("Klawiatury");
////        categroyList.add("Drukarki");
////        categroyList.add("Dyski");
////        categroyList.add("Akcesoria");
////        categroyList.add("Głosniki");
////        Map<String, Object> model = new HashMap<String, Object>();
//// 
////        
////        model.put("status",0);
////        model.put("menu", categroyList);
////        return new ModelAndView("/Sukces", model);
//        System.out.println("ddddddddddddddd");
//        //ModelAndView mv = new ModelAndView();
//        //mv.addObject("/Sukces", test);  
//
//        System.out.println("Dupaaaa2");
//        //model.put("status",0);
//        // model.put("Test", test);
//        //ModelAndView mv = new ModelAndView();
//        //mv.addObject("/Test", test);  
//        //return mv;
//
//        return new ModelAndView("/Sukces");
//
//    }

     @RequestMapping(value = "/test", method = RequestMethod.POST)
    public ModelAndView executeSubmitOnProductListPage2(@RequestParam("fs") int button,@ModelAttribute("Test") Test test, BindingResult result, SessionStatus status, HttpServletRequest request) {
       // Person person = new Person("Marcin", "Cichonski", "99-300", "Gandhiego", "Łódź");
        // Account account = new Account("login4", "password4", "email4", 1);

//        List<String> categroyList = new ArrayList<String>();
//        
//        categroyList.add("Monitory");
//        categroyList.add("Komputery");
//        categroyList.add("Laptopy");
//        categroyList.add("Myszki");
//        categroyList.add("Klawiatury");
//        categroyList.add("Drukarki");
//        categroyList.add("Dyski");
//        categroyList.add("Akcesoria");
//        categroyList.add("Głosniki");
//        Map<String, Object> model = new HashMap<String, Object>();
// 
//        
//        model.put("status",0);
//        model.put("menu", categroyList);
//        return new ModelAndView("/Sukces", model);
        System.out.println("ddddddddddddddd");
        //ModelAndView mv = new ModelAndView();
        //mv.addObject("/Sukces", test);  

        System.out.println("Dupaaaa2");
        //model.put("status",0);
        // model.put("Test", test);
        //ModelAndView mv = new ModelAndView();
        //mv.addObject("/Test", test);  
        //return mv;

        if(button==1)return new ModelAndView("/Sukces");
        
        return new ModelAndView("/Porazka");

    }

    
}
